﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
public class UIAdapt : MonoBehaviour {
    private UIAdapt adapt;
    private bool isdiedai;
    private float w;
    public float nw;
    public float h;
    public float sw;
    public float sh;
    public float sp;
    RectTransform rect;
    Transform[] forms;
    // Use this for initialization
    void Start () {
        isdiedai = true;
        rect = GetComponent<RectTransform>();
    }
    void GetWH()
    {
        w = rect.sizeDelta.x- sw;
        h = 0;
        foreach (Transform item in transform)
        {
            if (item.GetComponent<UIAdapt>())
            {
                adapt = item.GetComponent<UIAdapt>();
                if (w < adapt.nw)
                {
                    w = adapt.nw;
                }
                if (item.gameObject.activeSelf)
                    h += adapt.h + sh;
            }
            else
            {
                float _w = item.GetComponent<RectTransform>().sizeDelta.x;
                if (w <_w)
                {
                    w = _w;
                }
                h += item.GetComponent<RectTransform>().sizeDelta.y;
            }
        }
        nw = w + sw;
    }
	// Update is called once per frame
	void Update () {
        GetWH();
        rect.sizeDelta = new Vector2(nw, h);
        
    }
}
